//
//  GroupFunctionTableViewCell.m
//  Findif
//
//  Created by Mac on 2019/2/22.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "GroupFunctionTableViewCell.h"

@interface GroupFunctionTableViewCell ()

@property (nonatomic, weak)UIView * backView;
@property (nonatomic, strong)UIButton * oneButton;
@property (nonatomic, strong)UIButton * twoButton;
@property (nonatomic, strong)UIButton * threeButton;
@property (nonatomic, strong)UIButton * fourButton;
@property (nonatomic, strong)UILabel * oneLabel;
@property (nonatomic, strong)UILabel * twoLabel;
@property (nonatomic, strong)UILabel * threeLabel;
@property (nonatomic, strong)UILabel * fourLabel;


@end

@implementation GroupFunctionTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = ColorWithRGB(0xF4F5F6);
    
    UIView * backView = [UIView new];
    
    backView.backgroundColor  =ZRWhiteColor;
    backView.layer.cornerRadius = 5 * SCREENH6;
    backView.layer.masksToBounds = YES;
    backView.userInteractionEnabled = YES;
    
    self.backView = backView;
    
    [self.contentView addSubview:self.backView];
    
    self.oneButton = [self setupButtonWithImg:@"topic"];
    [self.backView addSubview:self.oneButton];
    self.twoButton = [self setupButtonWithImg:@"active"];
    [self.backView addSubview:self.twoButton];
    self.threeButton = [self setupButtonWithImg:@"photo"];
    [self.backView addSubview:self.threeButton];
    self.fourButton = [self setupButtonWithImg:@"Notice"];
    [self.backView addSubview:self.fourButton];
    
    self.oneLabel = [self setupLabelWith:@"话题"];
    [self.backView addSubview:self.oneLabel];
    self.twoLabel = [self setupLabelWith:@"活动"];
    [self.backView addSubview:self.twoLabel];
    self.threeLabel = [self setupLabelWith:@"相册"];
    [self.backView addSubview:self.threeLabel];
    self.fourLabel = [self setupLabelWith:@"公告"];
    [self.backView addSubview:self.fourLabel];
}


- (void)layoutSubviews{
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.centerX.mas_equalTo(self.contentView);
        make.width.mas_equalTo(345 * SCREENH6);
        make.height.mas_equalTo(80 * SCREENH6);
    }];
    
    [self.oneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backView).offset(25 * SCREENH6);
        make.top.mas_equalTo(self.backView).offset(9 * SCREENH6);
        make.width.height.mas_equalTo(40 * SCREENH6);
    }];
    
    [self.oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.oneButton);
        make.top.mas_equalTo(self.oneButton.mas_bottom).offset(8 * SCREENH6);
    }];
    
    [self.twoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.oneButton);
        make.leading.mas_equalTo(self.oneButton.mas_trailing).offset(45 * SCREENH6);
    }];
    
    [self.twoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.twoButton);
        make.top.mas_equalTo(self.twoButton.mas_bottom).offset(8 * SCREENH6);
    }];
    
    [self.threeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.twoButton);
        make.leading.mas_equalTo(self.twoButton.mas_trailing).offset(45 * SCREENH6);
    }];
    
    [self.threeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.threeButton);
        make.top.mas_equalTo(self.threeButton.mas_bottom).offset(8 * SCREENH6);
    }];
    
    [self.fourButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.threeButton);
        make.leading.mas_equalTo(self.threeButton.mas_trailing).offset(45 * SCREENH6);
    }];
    
    [self.fourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.fourButton);
        make.top.mas_equalTo(self.fourButton.mas_bottom).offset(8 * SCREENH6);
    }];
}


- (UIButton *)setupButtonWithImg:(NSString *)img{
    
    UIButton * button = [UIButton new];
    
    [button setImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickFunctionButton:) forControlEvents:UIControlEventTouchUpInside];
    
    
    return button;
}


- (UILabel *)setupLabelWith:(NSString *)string{
    
    UILabel * label = [UILabel new];
    
    label.text = string;
    label.textColor = ZRBlackColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    return label;
}


- (void)clickFunctionButton:(UIButton *)button{
    
    NSString * type;
    
    if (button == self.oneButton) {
        
        type = @"topic";
    }else if (button == self.twoButton){
        
        type = @"active";
    }else if (button == self.threeButton){
        
        type = @"album";
    }else if (button == self.fourButton){
        
        type = @"notice";
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickFunctionButtonWithType:)])
    {
        
        [self.delegate clickFunctionButtonWithType:type];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
